home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / include / stdlib.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-29  |  12.1 KB  |  462 lines

  1. /* Copyright (C) 1986-2001 by Digital Mars. $Revision: 1.1.1.3 $ */
  2. #if __SC__ || __RCC__
  3. #pragma once
  4. #endif
  5.  
  6. #ifndef __STDLIB_H
  7. #define __STDLIB_H 1
  8.  
  9. #if __cplusplus
  10. extern "C" {
  11. #endif
  12.  
  13. /* Define _CRTAPI1 (for compatibility with the NT SDK) */
  14. #ifndef _CRTAPI1
  15. #define _CRTAPI1 __cdecl
  16. #endif
  17.  
  18. /* Define _CRTAPI2 (for compatibility with the NT SDK) */
  19. #ifndef _CRTAPI2
  20. #define _CRTAPI2 __cdecl
  21. #endif
  22.  
  23. /* Define CRTIMP */
  24. #ifndef _CRTIMP
  25. #if defined(_WIN32) && defined(_DLL)
  26. #define _CRTIMP  __declspec(dllimport)
  27. #else
  28. #define _CRTIMP
  29. #endif
  30. #endif
  31.  
  32. #define EXIT_SUCCESS   0
  33. #define EXIT_FAILURE   1
  34.  
  35. #ifndef NULL
  36. #ifdef __cplusplus
  37. #define NULL 0
  38. #else
  39. #define NULL ((void *)0)
  40. #endif
  41. #endif
  42.  
  43. typedef unsigned size_t;
  44.  
  45. //#ifndef __STDC__
  46. #if !defined(_WCHAR_T_DEFINED)
  47. typedef unsigned short wchar_t;
  48. #define _WCHAR_T_DEFINED 1
  49. #endif
  50. //#endif
  51.  
  52. #pragma pack(__DEFALIGN)
  53. typedef struct _DIV { int  quot,rem; } div_t;
  54. typedef struct _LDIV { long quot,rem; } ldiv_t;
  55. #if __INTSIZE == 4
  56. typedef struct _LLDIV { long long quot,rem; } lldiv_t;
  57. #endif
  58. #pragma pack()
  59.  
  60. #if !__STDC__
  61.  
  62. #if !defined(ERANGE)
  63. #define ERANGE 34
  64. #endif
  65.  
  66. #define HUGE_VAL       __inf
  67.  
  68. #define RAND_MAX       32767
  69.  
  70. #define _div_t _DIV
  71. #define _ldiv_t _LDIV
  72.  
  73. #if __OS2__ && __INTSIZE == 4
  74. #define __CLIB __stdcall
  75. #else
  76. #define __CLIB __cdecl
  77. #endif
  78.  
  79. #ifdef __NT__
  80. extern int __CLIB    __locale_mbsize;
  81. #define MB_CUR_MAX    __locale_mbsize
  82. #else
  83. #define MB_CUR_MAX    1
  84. #endif
  85.  
  86. #endif
  87.  
  88. #define _MAX_PATH   260
  89. #define _MAX_DRIVE  3
  90. #define _MAX_DIR    256
  91. #define _MAX_FNAME  256
  92. #define _MAX_EXT    256
  93.  
  94. #if defined(_MT)
  95.  
  96. #if !__STDC__
  97. extern int *__CLIB _errno (void);
  98. #define errno (*_errno())
  99. #endif
  100. extern int *__CLIB __doserrno (void);
  101. #define _doserrno (*__doserrno ())
  102.  
  103. #else
  104.  
  105. #if !__STDC__
  106. extern int __CLIB errno;
  107. #endif
  108. extern int __CLIB _doserrno;
  109.  
  110. #endif
  111.  
  112. double __CLIB atof(const char *);
  113. #define _atold atof
  114. int    __CLIB atoi(const char *);
  115. long   __CLIB atol(const char *);
  116. double __CLIB strtod(const char *,char **);
  117. long double __CLIB strtold(const char *,char **);
  118. long   __CLIB strtol(const char *,char **,int);
  119. unsigned long  __CLIB strtoul(const char *,char **,int);
  120. #if __INTSIZE == 4
  121. long long   __CLIB atoll(const char *);
  122. long long   __CLIB strtoll(const char *,char **,int);
  123. unsigned long long __CLIB strtoull(const char *,char **,int);
  124. #endif
  125. int    __CLIB rand(void);
  126. void   __CLIB srand(unsigned);
  127. int    __CLIB random(int num);
  128. void    __CLIB randomize(void);
  129. _CRTIMP void * __CLIB calloc(size_t,size_t);
  130. _CRTIMP void   __CLIB free(void *);
  131. _CRTIMP void * __CLIB malloc(size_t);
  132. _CRTIMP void * __CLIB realloc(void *,size_t);
  133. void   __CLIB abort(void);
  134. int    __CLIB atexit(void (*)(void));
  135. void   __CLIB exit(int);
  136. void   __CLIB _exit(int);
  137. void   __CLIB _Exit(int);
  138.  
  139. _CRTIMP char * __CLIB getenv(const char *);
  140. int    __CLIB system(const char *);
  141. void * __CLIB bsearch(const void *,const void *,size_t,size_t,
  142.        int (__CLIB *)(const void *,const void *));
  143. void   __CLIB qsort(void *,size_t,size_t,
  144.        int (__CLIB *)(const void *,const void *));
  145. int    __CLIB abs(int);
  146. long   __CLIB labs(long);
  147. div_t  __CLIB div(int,int);
  148. ldiv_t __CLIB ldiv(long,long);
  149. #if __INTSIZE == 4
  150. long long   __CLIB llabs(long long);
  151. lldiv_t __CLIB lldiv(long long, long long);
  152. #endif
  153. int    __CLIB mblen(const char *, size_t);
  154. size_t __CLIB _mbstrlen(const char *);
  155. int    __CLIB mbtowc(wchar_t *, const char *, size_t);
  156. int    __CLIB wctomb(char *, wchar_t);
  157. size_t __CLIB mbstowcs(wchar_t *, const char *, size_t);
  158. size_t __CLIB wcstombs(char *, const wchar_t *, size_t);
  159. void   __CLIB perror(const char *);
  160. #ifndef toupper
  161. int    __CLIB toupper(int);
  162. #endif
  163. #ifndef tolower
  164. int    __CLIB tolower(int);
  165. #endif
  166.  
  167. unsigned       __CLIB _rotl(unsigned,int);
  168. unsigned       __CLIB _rotr(unsigned,int);
  169. unsigned long  __CLIB _lrotl(unsigned long,int);
  170. unsigned long  __CLIB _lrotr(unsigned long,int);
  171. char * __CLIB _fullpath(char *buf,const char *path,size_t buflen);
  172.  
  173. #if !__STDC__
  174. #define fullpath       _fullpath
  175. #endif
  176.  
  177. extern int __CLIB sys_nerr;
  178. extern char * __CLIB sys_errlist[];
  179. #define _sys_nerr sys_nerr
  180. #define _sys_errlist sys_errlist
  181.  
  182. #ifndef __STDC__
  183.  
  184. #if __INTSIZE == 2
  185. int    __CLIB __far _fmblen(const char __far *,size_t);
  186. int    __CLIB __far _fmbtowc(wchar_t __far *,const char __far *,size_t);
  187. int    __CLIB __far _fwctomb(char __far *,wchar_t);
  188. size_t __CLIB __far _fmbstowcs(wchar_t __far *, const char __far *, size_t);
  189. size_t __CLIB __far _fwcstombs(char __far *, const wchar_t __far *, size_t);
  190. #else
  191. int    __CLIB _fmblen(const char __far *,size_t);
  192. int    __CLIB _fmbtowc(wchar_t __far *,const char __far *,size_t);
  193. int    __CLIB _fwctomb(char __far *,wchar_t);
  194. size_t __CLIB _fmbstowcs(wchar_t __far *, const char __far *, size_t);
  195. size_t __CLIB _fwcstombs(char __far *, const wchar_t __far *, size_t);
  196. unsigned long long __CLIB strtoull(const char *,char **,int);
  197. #endif
  198.  
  199. #if __INTSIZE == 2
  200. extern char __far *__cdecl _pgmptr;
  201. #else
  202. extern char *__cdecl _pgmptr;
  203. extern wchar_t *__cdecl _wpgmptr;
  204. #endif
  205.  
  206. extern unsigned int __cdecl _osver;
  207. #ifndef __NT__
  208. extern unsigned short __cdecl _psp;
  209. extern unsigned char __cdecl _osmajor;
  210. extern unsigned char __cdecl _osminor;
  211. #endif
  212.  
  213. #ifdef _DLL
  214. extern int * __CLIB __p___argc(void);
  215. extern char *** __CLIB __p___argv(void);
  216. extern wchar_t *** __CLIB __p___wargv(void);
  217. #define __argc    (*__p___argc())
  218. #define __argv    (*__p___argv())
  219. #define __wargv    (*__p___wargv())
  220. #else
  221. extern int __cdecl __argc;
  222. extern char __cdecl ** __argv;
  223. extern wchar_t __cdecl ** __wargv;
  224. #endif
  225.  
  226. #if defined (_WIN32)
  227. wchar_t ** __CLIB __wparsecmdline(const wchar_t *, int *);
  228. char ** __CLIB __parsecmdline(const char *, int *);
  229. #endif
  230.  
  231. #if defined(_WINDOWS) || defined(__NT__)
  232. extern unsigned char __cdecl _winmajor;
  233. extern unsigned char __cdecl _winminor;
  234. extern unsigned int __cdecl _winver;
  235. #endif
  236.  
  237. #define _DOS_MODE 0
  238. #define _OS2_MODE 1
  239. #define _WIN_MODE 2
  240.  
  241. #if !__STDC__
  242. #define DOS_MODE _DOS_MODE
  243. #define OS2_MODE _OS2_MODE
  244. #define WIN_MODE _WIN_MODE
  245. #endif
  246.  
  247. extern unsigned char __cdecl _osmode;
  248.  
  249. #define _REAL_MODE 0
  250. #define _PROT_MODE 1
  251.  
  252. extern unsigned char __cdecl _cpumode;
  253.  
  254. extern int __cdecl _fmode;
  255.  
  256. void __cdecl _splitpath(const char *, char *,char *, char *, char *);
  257. void __cdecl _makepath(char *, const char *,const char *, const char *, const char *);
  258. void __cdecl _searchenv(const char *filename, const char *varname, char *pathname);
  259.  
  260. #include <heapstat.h>
  261.  
  262. _CRTIMP int __cdecl _heapchk(void);
  263. _CRTIMP int __cdecl _heapset(unsigned);
  264. #if __INTSIZE == 2
  265. int __cdecl _heapadd(void __far *,size_t);
  266. #else
  267. int __cdecl _heapadd(void *,size_t);
  268. #endif
  269. int __cdecl _heapmin(void);
  270.  
  271. #ifdef __NT__
  272. #define _expand realloc
  273. #else
  274. void * __cdecl _expand(void *,size_t);
  275. #endif
  276.  
  277. _CRTIMP size_t __cdecl _msize(void *);
  278.  
  279. #if __LARGE__ || __COMPACT__
  280. void * __cdecl _fmalloc(size_t);
  281. void * __cdecl _fcalloc(size_t,size_t);
  282. void * __cdecl _frealloc(void *,size_t);
  283. void __cdecl _ffree(void *);
  284. size_t __cdecl _fmsize(void *);
  285. unsigned long __cdecl coreleft(void);
  286. unsigned long __cdecl farcoreleft(void);
  287. #if _WINDOWS
  288. void __near * __cdecl _nmalloc(size_t);
  289. void __near * __cdecl _ncalloc(size_t,size_t);
  290. void __near * __cdecl _nrealloc(void __near *,size_t);
  291. void __cdecl _nfree(void __near *);
  292. size_t __cdecl _nmsize(void __near *);
  293. size_t __cdecl _memmax(void);
  294. size_t __cdecl _memavl(void);
  295. unsigned int __cdecl _freect(size_t);
  296. #endif
  297. #else
  298. void * __cdecl _nmalloc(size_t);
  299. void * __cdecl _ncalloc(size_t,size_t);
  300. void * __cdecl _nrealloc(void *,size_t);
  301. void __cdecl _nfree(void *);
  302. size_t __cdecl _nmsize(void *);
  303. size_t __cdecl _memmax(void);
  304. size_t __cdecl _memavl(void);
  305. unsigned int __cdecl _freect(size_t);
  306. unsigned __cdecl coreleft(void);
  307. unsigned long __cdecl farcoreleft(void);
  308. #if __INTSIZE == 2 || (!__NT__ && !__OS2__)
  309. void __far * __cdecl _fmalloc(size_t);
  310. void __far * __cdecl _fcalloc(size_t,size_t);
  311. void __far * __cdecl _frealloc(void __far *,size_t);
  312. void __cdecl _ffree(void __far *);
  313. size_t __cdecl _fmsize(void __far *);
  314. #endif
  315. #endif
  316.  
  317. #if __INTSIZE == 2
  318. void __huge *_halloc (long, size_t);
  319. void _hfree (void __huge *);
  320. #endif
  321.  
  322. char * __CLIB itoa(int,char *,int);
  323. char * __CLIB _itoa(int, char *,int);
  324. char * __CLIB ltoa(long, char *, int);
  325. char * __CLIB _ltoa(long, char *,int);
  326. char *  __CLIB ultoa(unsigned long, char *, int);
  327. char * __CLIB ecvt(double,int,int *,int *);
  328. char * __CLIB fcvt(double,int,int *,int *);
  329. char * __CLIB _fcvt(double,int,int *,int *);
  330. char * __CLIB gcvt(double,int,char *);
  331. void * __cdecl sbrk(size_t);
  332. void   __CLIB swab(char *,char *,size_t);
  333. float  __CLIB strtof(const char *,char **);
  334. #define _swab swab
  335. #define _ecvt ecvt
  336. #define _gcvt gcvt
  337. #if !_WIN32
  338. #define strtold        strtod
  339. #endif
  340. #define _strtold       strtold
  341. #define _ultoa ultoa
  342. #if _MSDOS
  343. void __ss *    __CLIB alloca(size_t);
  344. #else
  345. void *    __CLIB alloca(size_t);
  346. #endif
  347. #define _alloca alloca
  348. size_t __CLIB stackavail(void);
  349. size_t __CLIB _chkstack(void);
  350. #define _stackavail stackavail
  351.  
  352. #if __INTSIZE == 4
  353. int __cdecl _fatexit (void (__cdecl *func)(void));
  354. typedef void (__cdecl * _fonexit_t)(void);
  355. _fonexit_t __cdecl _fonexit (_fonexit_t func);
  356. #else
  357. int __cdecl __far _fatexit (void (__cdecl __far *func)(void));
  358. typedef void (__cdecl __far * _fonexit_t)(void);
  359. _fonexit_t __cdecl __far _fonexit (_fonexit_t func);
  360. #endif
  361.  
  362. typedef void (__cdecl * _onexit_t)(void);
  363. _onexit_t __cdecl _onexit (_onexit_t func);
  364.  
  365. #ifndef __STDC__
  366. #define onexit _onexit
  367. #endif
  368.  
  369. #if __INTSIZE == 2
  370. void __far * __far __CLIB __mallocf(size_t);
  371. void        __far __CLIB __freef(void __far *);
  372. #endif
  373. _CRTIMP int            __CLIB putenv(const char *);
  374.  
  375. #define _putenv putenv
  376.  
  377. /* Min and Max macros useful in both C and CPP */
  378. #define __max(a,b)            (((a) > (b)) ? (a) : (b))
  379. #define __min(a,b)            (((a) < (b)) ? (a) : (b))
  380.  
  381.  
  382. #ifndef __cplusplus
  383.  
  384. #ifndef max
  385. #define max(a,b)            (((a) > (b)) ? (a) : (b))
  386. #endif
  387.  
  388. #ifndef min
  389. #define min(a,b)            (((a) < (b)) ? (a) : (b))
  390. #endif
  391. #endif
  392.  
  393. extern int (__far __cdecl *_malloc_handler)(void);
  394. extern char * __cdecl _envptr;
  395. #ifdef _DLL
  396. _CRTIMP char ***__CLIB _p_environ (void);
  397. #define _environ (*_p_environ())
  398. #else
  399. extern char ** __cdecl _environ;
  400. #endif
  401.  
  402. #define environ _environ
  403.  
  404. #ifdef __NT__
  405. #define _aenvptr _envptr
  406. extern wchar_t * __cdecl _wenvptr;
  407. #ifdef _DLL
  408. _CRTIMP wchar_t ***__CLIB _p_wenviron (void);
  409. #define _wenviron (*_p_wenviron())
  410. #else
  411. extern wchar_t ** __cdecl _wenviron;
  412. #endif
  413.  
  414. #define wenviron _wenviron
  415. #endif
  416.  
  417. #if !(defined (_WINDOWS) || defined (__NT__) || defined (DOS386))
  418. extern int __CLIB _fileinfo;
  419. #endif
  420.  
  421. #if M_UNIX || M_XENIX
  422. extern char * __cdecl optarg;
  423. extern int __cdecl optind;
  424. extern int __cdecl opterr;
  425. extern int __cdecl optopt;
  426. #endif
  427.  
  428. #endif
  429.  
  430. #ifdef __NT__
  431. #ifndef __STDC__
  432. int __CLIB _wtoi(const wchar_t *);
  433. long __CLIB _wtol(const wchar_t *);
  434. double __CLIB wcstod(const wchar_t *, wchar_t **);
  435. long double __CLIB wcstold(const wchar_t *, wchar_t **);
  436. long __CLIB wcstol(const wchar_t *, wchar_t **, int);
  437. unsigned long __CLIB wcstoul(const wchar_t *, wchar_t **, int);
  438. long long __CLIB wcstoll(const wchar_t *, wchar_t **, int);
  439. unsigned long long __CLIB wcstoull(const wchar_t *, wchar_t **, int);
  440. _CRTIMP wchar_t * __CLIB _wgetenv(const wchar_t *);
  441. int __CLIB _wsystem(const wchar_t *);
  442. wchar_t * __CLIB _itow(int, wchar_t *, int);
  443. wchar_t * __CLIB _ltow(long, wchar_t *, int);
  444. wchar_t * __CLIB _ultow(unsigned long, wchar_t *, int);
  445. wchar_t * __CLIB _wfullpath(wchar_t *, const wchar_t *, size_t);
  446. void __CLIB _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *);
  447. void __CLIB _wperror(const wchar_t *);
  448. _CRTIMP int __CLIB _wputenv(const wchar_t *);
  449. void __CLIB _wsearchenv(const wchar_t *, const wchar_t *, wchar_t *);
  450. void __CLIB _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
  451. #define itow _itow
  452. #define ltow _ltow
  453. #define ultow _ultow
  454. #endif
  455. #endif
  456.  
  457. #if __cplusplus
  458. }
  459. #endif
  460.  
  461. #endif
  462.